@extends("layouts.app")
@section('content')
<script src="{{env('URL_SUB', '')}}/static/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="{{env('URL_SUB', '')}}/static/datetimepicker/bootstrap-datetimepicker.fr.js"></script>
<link href="{{env('URL_SUB', '')}}/static/datetimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet">
<section class="content-header">
    <h1>
        用户管理
    </h1>
    <ol class="breadcrumb">
        <li><a href="/dashboard"><i class="fa fa-dashboard"></i>家</a></li>
        <li><a href="#">用户管理</a></li>
        <li class="active">用户列表</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">搜索</h3>
                    <div class="box-tools"></div>
                </div>
                <div class="box-body">
                    <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                        <form class="form-inline" role="form" method="get" id="frmSearch">
                            <div class="form-group">
                                <input type="text" name="nickname" class="form-control input-sm" style="width:9em" placeholder="请输入昵称">
                            </div>&nbsp;
                            <div class="form-group">
                                <input type="text" name="openid" class="form-control input-sm" style="width:9em" placeholder="请输入openid">
                            </div>&nbsp;
                            <div class="form-group">
                                <select class="form-control type form-inline" name="status">
                                    <option value="">是否留资</option>
                                    <option value="0">未留资</option>
                                    <option value="1">已留资</option>
                                </select>
                            </div>&nbsp;
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputEmail3"></label>
                                <input type="text" class="form-control pull-right datepicker" name="starttime" data-date-format="yyyy-mm-dd" placeholder="请输入开始日期">
                            </div>
                            &nbsp;
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputEmail3"></label>
                                <input type="text" class="form-control pull-right datepicker" name="endtime" placeholder="请输入截止日期">
                            </div>
                            &nbsp;
                            <input type="submit" class="btn  btn-success" value="搜索">&nbsp;
                            <a href="{{env('URL_SUB', '')}}/admin/hillclimb/userexport?{{$_SERVER["QUERY_STRING"]}}" class="btn btn-primary">导出</a>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        $('.datepicker').datetimepicker({
            autoclose: true,
            format: 'yyyy-mm-dd',
            minView : 2
        });
        $(function() {

            var search = location.search.substring(1);
            if (search) {
                try {
                    var query = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');

                    $.each(query, function(k, v) {
                        $('[name=' + k + ']').val(v);
                    });
                } catch (e) {
                    console.log(e);
                }

            }
        })
    </script>
    <div class="row">
        <div class="col-sm-12">
            <div class="box">
                <div class="box-header with-border box-danger">
                    <h3 class="box-title">用户列表</h3>
                </div>

                <!-- /.box-body -->
                <div class="box-body">
                    <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                        <div class="row">
                            <div class="col-sm-6"></div>
                            <div class="col-sm-6"></div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="example2" class="table table-bordered table-hover dataTable text-center" role="grid"
                                       aria-describedby="example2_info">
                                    <thead>
                                        <tr role="row">

                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Browser: activate to sort column ascending">
                                                userID
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Browser: activate to sort column ascending">
                                                昵称
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Platform(s): activate to sort column ascending">
                                                头像
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                openid
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                是否留资
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                姓名
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                手机号码
                                            </th>
                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                创建时间
                                            </th>
                                            <th>
                                                活动数据
                                            </th>
<!--                                            <th class="sorting col-sm-4" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Browser: activate to sort column ascending">
                                                操作
                                            </th>-->
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($list as $value)
                                        <tr role="row" class="odd">

                                            <td>{{$value->id}}</td>
                                            <td>{{$value->nickname}}</td>
                                            <td><img src="{{$value->avatar}}" alt="" width="50px"></td>
                                            <td>{{$value->openid}}</td>
                                            <td>@if($value->iscapital == '1')已留资@else未留资@endif</td>
                                            <td>{{$value->realname}}</td>
                                            <td>{{$value->telphone}}</td>
                                            <td>{{$value->created_at}}</td>
                                            <td>
                                                <a href="{{env('URL_SUB', '')}}/admin/hillclimb/rankdetail?userid={{$value->id}}" class="btn btn-primary" target="_blank">活动详细数据</a>
                                            </td>
<!--                                                <td>

                                            </td>-->


                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        @include("layouts.page",['paginator'=>$list])
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="box">
                <div class="box-header with-border box-danger">
                    <h3 class="box-title">意外险卡券数量设置</h3>
                </div>

                <!-- /.box-body -->
                <form class="form-horizontal" method="post" id='form1'>
                    {{csrf_field()}}
                    <div class="box-body" id="container">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">卡券数量</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="code_num" value="{{env('CODE_NUM','')}}">
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer text-center">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn btn-success btn-set">提交</button>
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </div>
</section>
<script src="{{env('URL_SUB', '')}}/bower_components/AdminLTE/plugins/iCheck/icheck.min.js"></script>
<script src="{{env('URL_SUB', '')}}/bower_components/AdminLTE/plugins/iCheck/icheck.js"></script>
<script type="text/javascript">
    var url_base = "{{env('URL_SUB', '')}}";
    $(function() {
        $(".btn-set").click(function() {
            var code_num = $("input[name=code_num]").val();
            console.log(code_num);
            $.ajax({
                url: url_base+'/admin/hillclimb/setcodenum',
                type: 'POST',
                data: {code_num: code_num},
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('input[name=_token]').val()
                },
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                error: function() {
                    //alert('Error loading PHP document');
                },
                success: function(json) {
                    var r = confirm(json.msg);
                    if (r == true) {
                        window.location.reload();
                    }
                }
            });
            return false;
        });
    })
</script>
@endsection
